<?php

// AudioShout 0.1.0 Alpha

// Global multi-server settings. Modify these values only if you plan on using more than one server ("node") to host uploads. See the documentation for more details.
// Set $multiserver to true if running this script in a multi-server environment. Note that the current multi-node architecture only works if each node is on its own subdomain.
// Then set $servername to the subdomain of the node on which this script is installed, and set $SQLMaster to the subdomain of the node containing the primary database server.
$multiserver = false;
if ($multiserver == true)
{
// Change the two below values only after setting $multiserver above to true. See above comments or documentation for more details.
$servername = 'us1';
$SQLMaster = 'us1';
} else {
	$servername = "www";
	$SQLMaster = "www";
}

function pickhost()
// Determine to which node an end user should be sent based on their country. Requires the Net_GeoIP PEAR package. See the documentation for usage details.
{
if ($multiserver == true)
			{
			require_once('Net/GeoIP.php');
			$geoip = Net_GeoIP::getInstance($GeoIPPath);
			$country = $geoip->lookupCountryCode($_SERVER['REMOTE_ADDR']);
			$server = $servername;
			switch ($country)
				{
				case 'NL':
				case 'BE':
				case 'DE':
				case 'IT':
				case 'PL':
				case 'PT':
					$server = 'eu';
					break;
				case 'US':
					$server = 'us1';
					break;
				case 'GB':
				case 'FR':
					$server = 'uk';
					break;
				default:
					$query = "SELECT hostname FROM nodes WHERE active=1 ORDER BY rand() LIMIT 1";
					$mysqli = dbconnect();
					$statement = $mysqli->stmt_init();
					if ($statement->prepare($query))
						{
							$statement->execute();
						$server = dbresult($statement,0);
						$statement->close();
						$mysqli->close();
						} else {
						$statement->close();
						$mysqli->close();
						$server = $servername;
						}
					break;
				}
return $server;
			} else {
			$server = $servername;
			}
}
$server = pickhost();

?>
